﻿using System;
using System.Collections.Generic;
using System.Text;
using FileWatcher;
using System.IO;
using System.Security.Permissions;
using EmailSendWizard;
using XMLconfig;
using DatabaseInsertAndExportLibrary;


namespace WindowsSevicerTest
{
    public class DataFileMonitor : FileWatchers
    {
        public DataFileMonitor(string path, string extension)
            : base(path, extension)
        {
        }


        //watch the .csv file appeared.
        public override void OnChanged(object source, FileSystemEventArgs e)
        {
            InsertToDatabase iDB = new InsertToDatabase(e.FullPath);
            //Implement insert to data base
            Console.WriteLine("Insert to Database");
            ////Write an event log
            //Console.WriteLine("Write an event log");
            //Send an email to remind
            SendAnEmail();
            Console.WriteLine("Sent email");
        }
        public void SendAnEmail()
        {
            EmailSentAction sent = new EmailSentAction("smtp.gmail.com", "autofinacedatacapture@gmail.com", "Assignment", 587, true);
            string dateString = DateTime.Now.ToShortDateString();
            XmlConfig email = new XmlConfig();
            sent.SendMail("AutoFinaceDataCapture@gmail.com", email.getMailFromConfig(), "Report of " + dateString + " had released.", "Success received");
        }

    }
}
